package fr.alesia.deepstack.factory;

import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;

import fr.alesia.deepstack.data.PlayerDao;
import fr.alesia.deepstack.data.RankingDao;
import fr.alesia.deepstack.data.TournamentDao;
import fr.alesia.deepstack.data.jdo.PlayerDaoJdo;
import fr.alesia.deepstack.data.jdo.RankingDaoJdo;
import fr.alesia.deepstack.data.jdo.TournamentDaoJdo;

public abstract class DaoFactory {

	private static PersistenceManagerFactory persistenceManagerFactory = null;
	
	public static synchronized PersistenceManager getPersistenceManager(){
		
		if(persistenceManagerFactory == null){
			persistenceManagerFactory =
				JDOHelper.getPersistenceManagerFactory("transactions-optional");
		}
		return persistenceManagerFactory.getPersistenceManager();
	}
	
	public static PlayerDao getPlayerDao(){
		
		return PlayerDaoJdo.getInstance();
	}
	
	public static TournamentDao getTournamentDao(){
		
		return TournamentDaoJdo.getInstance();
	}
	
	public static RankingDao getRankingDao(){
		
		return RankingDaoJdo.getInstance();
	}
}
